package com.smallyu.order.exception.exceptionHandler;

import com.smallyu.order.constant.YuHttpStatus;
import com.smallyu.order.core.YuResult;
import com.smallyu.order.exception.YuTokenException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: small-yu
 * @Package: com.smallyu.order.exception
 * @Project: order
 * @Date: 2024/4/11
 * @Time: 2:10
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class YuException {

    @ExceptionHandler(YuTokenException.class)
    public YuResult handleTokenException(YuTokenException e, HttpServletRequest request){
        log.error("请求地址:{},原因:{}",request.getRequestURI(),e.getMessage());
        return YuResult.error(YuHttpStatus.UNAUTHORIZED,e.getMessage());
    }
}
